package com.zjc.yohoshop;

import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.RadioGroup;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.zjc.lib_core.base.BaseActivity;
import com.zjc.yohoshop.bean.BaseEntity;
import com.zjc.yohoshop.bean.HomeMenuEntity;
import com.zjc.yohoshop.di.compont.DaggerMainCompont;
import com.zjc.yohoshop.di.modules.MainModules;
import com.zjc.yohoshop.mvp.contract.MainContract;
import com.zjc.yohoshop.mvp.persenter.MainPresenter;
import com.zjc.yohoshop.mvp.view.fragment.HomeFragment;

public class MainActivity extends BaseActivity<MainPresenter> implements MainContract.IMaianView {

    private SlidingMenu slidingMenu;
    private RadioGroup rg_main_bottom;

    /**
     * 事件监听方法
     */
    @Override
    public void initListener() {
        /**
         * 单选按钮组监听
         */
        rg_main_bottom.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                Fragment fragment = null;
                switch (checkedId){
                    case R.id.rb_main_homepage:
                        fragment = new HomeFragment();
                        break;
                    case R.id.rb_main_category:
                        break;
                    case R.id.rb_main_see:
                        break;
                    case R.id.rb_main_mine:
                        break;
                }
                if (fragment != null) {
                    getSupportFragmentManager().beginTransaction().replace(R.id.fl_main, new HomeFragment()).commit();
                }
            }
        });
        /**
         * 默认选中
         */
        rg_main_bottom.check(R.id.rb_main_homepage);

    }


    @Override
    public int layoutID() {
        return R.layout.activity_main;
    }

    /**
     * 初始化视图
     */
    @Override
    public void init() {
        rg_main_bottom = (RadioGroup) findViewById(R.id.rg_main_bottom);
        initmenu();
    }


    private void initmenu() {
        //TODO 1:创建菜单对象
        slidingMenu = new SlidingMenu(this);
        //TODO 2：设置属性
        //SlidingMenu.RIGHT   SlidingMenu.LEFT
        slidingMenu.setMode(SlidingMenu.LEFT);//设置从哪边出来
        //TOUCHMODE_FULLSCREEN全屏;TOUCHMODE_MARGIN边界;TOUCHMODE_NONE不能滑动
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);//不能滑动
        slidingMenu.setBehindOffset(200);//单位是像素px 侧滑菜单滑出后，界面剩余的宽度。
        slidingMenu.setMenu(R.layout.activity_home);
        slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);//绑定到指定的Context
    }

    @Override
    public void initData() {
        p.requestMenu();
        initListener();
    }

    @Override
    public void setupDagger() {
        DaggerMainCompont.builder()
                .mainModules(new MainModules(this))
                .build().inject(this);
    }

    @Override
    public void success(BaseEntity baseEntity) {
        HomeMenuEntity menuEntity = (HomeMenuEntity) baseEntity;
        //在主线程->刷新UI
        Log.e("ZJC","MainActivity:"+menuEntity.values.size());
        //刷新适配器
    }

    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }
}
